<?php

namespace app\store\controller\store;

use app\store\controller\Controller;
use app\store\model\store\Letter as LetterModel;

/**
 * 站内信控制器
 * Class StoreUser
 * @package app\store\controller
 */
class Letter extends Controller
{
    /**
     * 站内信列表
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function index()
    {
        $model = new LetterModel;
        $list = $model->getList($this->request->param());
        return $this->fetch('index', compact('list'));
    }


    /**
     * 站内信列表
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function detail($id)
    {
        $model = LetterModel::detail($id);
        return $this->fetch('index', compact('model'));
    }

    /**
     * 阅读站内信
     * @param $user_id
     * @return array
     * @throws \think\exception\DbException
     */
    public function see($id)
    {
        // 管理员详情
        $model = LetterModel::detail($id);
        $model->setSee();
        //return $this->renderSuccess('操作成功');
    }

    /**
     * 删除站内信
     * @param $user_id
     * @return array
     * @throws \think\exception\DbException
     */
    public function delete($id)
    {
        // 管理员详情
        $model = LetterModel::detail($id);
        if (!$model->setDelete()) {
            return $this->renderError($model->getError() ?: '删除失败');
        }
        return $this->renderSuccess('删除成功');
    }


}
